package org.wzys.Controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.wzys.Pojo.PageResult;
import org.wzys.Pojo.Result;
import org.wzys.Pojo.User;
import org.wzys.Pojo.UserQueryparm;
import org.wzys.Service.UserService;

import javax.naming.ldap.PagedResultsControl;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    //实现管理员（前端判断role）的列表学生信息查询
    @GetMapping
    public Result getpageinfo(UserQueryparm userQueryparm) {
        log.info("查询学生信息的参数{}", userQueryparm);
        PageResult pageresult = userService.getpageinfo(userQueryparm);
        return Result.success(pageresult);
    }

    //实现管理员（前端判断role）的删除学生信息
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        log.info("请求删除参数ids: {}", ids);
        userService.delete(ids);
        return Result.success();
    }

    //实现管理员（前端判断role）的添加学生信息
    @PostMapping
    public Result add(@RequestBody User user) {
        log.info("请求添加参数user: {}", user);
        userService.add(user);
        return Result.success();
    }
    //实现管理员（前端判断role）的修改学生信息,数据回显
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        log.info("请求查询id: {}", id);
        User user = userService.getbyid(id);
        return Result.success(user);
    }
    //实现管理员（前端判断role）的修改学生信息
    @PutMapping
    public Result update(@RequestBody User user) {
        log.info("请求修改参数user: {}", user);
        userService.update(user);
        return Result.success();
    }

}
